/**
 * 
 */
package com.vivid.dynamics.gametrials.noengine.common;

import android.app.Activity;
import android.content.Intent;
import android.view.View;

/**
 * 
 * @author kusanagihk<br/>
 * created at: Nov 26, 2011::3:44:51 PM
 */
public class ButtonUtil {
	
	static final String TAG=ButtonUtil.class.getSimpleName();
	
	/**
	 * this method returns an instance of View.OnClickListener that 
	 * simply do nothing~<p/>
	 * <b>PS</b>. this method is useful when your button or UI doesn't 
	 * need to respond to anything (but if this is the case... when create
	 * a UI that seems to RECEIVE user click??? illogical?)
	 * @return
	 */
	public static View.OnClickListener getSimpleOnClickListener() {
		return new View.OnClickListener() {
			
			public void onClick(View v) {
				// do nothing
			}
		};
	}
	
	/**
	 * this method returns an instance of View.OnClickListener that will 
	 * forward to the given Intent once an "OnClick" event occurs 
	 * @param pActivity
	 * @param pTargetIntent
	 * @param pEndCurrentActivity
	 * @return
	 */
	public static View.OnClickListener getIntentForwardingOnClickListener(
		final Activity pActivity, final Intent pTargetIntent, final boolean pEndCurrentActivity) {
		
		return new View.OnClickListener() {
			
			public void onClick(View v) {
				if (pTargetIntent!=null) {
					pActivity.startActivity(pTargetIntent);
					/*
					 * end the Activity when necessary (ie. once started a new
					 * Activity; the current/previous Activity will be 
					 * destroyed
					 */
					if (pEndCurrentActivity) {
						pActivity.finish();
					}
					
				} else {
					// do logging...
					LogUtil.getInstance(pActivity).w(
						TAG, "[getIntentForwardingOnClickListener] the Intent object is NULL~~~");
				}	
			}
		};
	}
	
}
